#include<bits/stdc++.h>
using namespace std;
const int N=5e3+5,mod=998244353;
int n,m,a[N],ans;
struct node{
	int a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11;
	bool friend operator<(node i,node j)
	{
		if(i.a1==j.a1) if(i.a2==j.a2) if(i.a3==j.a3) if(i.a4==j.a4) if(i.a5==j.a5) if(i.a6==j.a6) if(i.a7==j.a7) if(i.a8==j.a8) if(i.a9==j.a9) if(i.a10==j.a10) return i.a11<j.a11; 
		else return i.a10<j.a10;
		else return i.a9<j.a9;
		else return i.a8<j.a8;
		else return i.a7<j.a7; 
		else return i.a6<j.a6;
		else return i.a5<j.a5; 
		else return i.a4<j.a4;
		else return i.a3<j.a3;
		else return i.a2<j.a2;
		return i.a1<j.a1;
	}
}w;
map<node,bool>q;
void dfs()// 1 2 5 14 42 132 429 1430 4862 16796 58786
{
	w.a1=a[1];
	w.a2=a[2];
	w.a3=a[3];
	w.a4=a[4];
	w.a5=a[5];
	w.a6=a[6];
	w.a7=a[7];
	w.a8=a[8];
	w.a9=a[9];
	w.a10=a[10];
	w.a11=a[11];
	if(!q[w])
		++ans,q[w]=1;
	else
		return;
	for(int i=1;i<n;++i)
	{
		 if(a[i]!=a[i+1])
		 {
		 	int lst=a[i],lst1=a[i+1];
		 	a[i]=max(a[i],a[i+1]);
			a[i+1]=max(a[i],a[i+1]);
			dfs();
			a[i]=lst;
			a[i+1]=lst1; 
		 }
	 } 
 } 
int main()
{
	freopen("after.in","r",stdin);
	freopen("after.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	dfs();
	cout<<ans;
	return 0;
 } 
